#ifndef MAPEDITOR_H
#define MAPEDITOR_H

// Libraries
#include "state.h"
#include "map.h"
#include "singleton.h"

// Classes
class MapEditorState : public CState, public Singleton<MapEditorState>
{
	public:
		enum ElementType 
		{
			NEWMAP_WINDOW,
			NEWMAP_FILE,
			NEWMAP_WIDTH,
			NEWMAP_HEIGHT,
			NEWMAP_CREATE,
			NEWMAP_CANCEL,
			NEWMAP_ERROR,
			BRUSHOPTIONS_WINDOW,
			BRUSHOPTIONS_WALL,
			BRUSHOPTIONS_PVP,
			BRUSHOPTIONS_ZONE,
			BRUSHOPTIONS_EVENTTYPE,
			BRUSHOPTIONS_EVENTDATA,
			BRUSHOPTIONS_FILTERTEXTURE,
			BRUSHOPTIONS_FILTERWALL,
			BRUSHOPTIONS_FILTERZONE,
			BRUSHOPTIONS_FILTERPVP,
			BRUSHOPTIONS_FILTEREVENTTYPE,
			BRUSHOPTIONS_FILTEREVENTDATA,
			BRUSHOPTIONS_FILTERCLOSE,
			LOADMAP_WINDOW,
			TEXTUREPALETTE_WINDOW,
			TEXTURES_ID=100,
		};
		enum StateType 
		{
			STATE_MAIN,
			STATE_NEWMAP,
			STATE_LOADMAP,
			STATE_TEXTUREPALETTE,
			STATE_BRUSHOPTIONS,
		};
		enum FilterType 
		{
			FILTER_TEXTURE,
			FILTER_WALL,
			FILTER_PVP,
			FILTER_ZONE,
			FILTER_EVENTTYPE,
			FILTER_EVENTDATA,
			FILTER_COUNT
		};

		bool Show();
		bool Hide();

		bool HandleKeyPress(EKEY_CODE TKey);
		bool HandleKeyRelease(EKEY_CODE TKey) { return false; }
		bool HandleMousePress(int TButton, int TMouseX, int TMouseY);
		void HandleMouseRelease(int TButton, int TMouseX, int TMouseY) { }
		void HandleMouseWheel(float TDirection);
		void HandleMouseMotion(int TMouseX, int TMouseY);
		void HandleGUI(EGUI_EVENT_TYPE TEventType, IGUIElement *TElement);

		void Update(u32 TDeltaTime);
		void Draw();

	private:

		void CloseWindow(int TElement);
		void CloseMap();

		// New
		void InitNewMap();
		void CreateMap();

		// Loading
		void InitLoadMap();

		// Texture palette
		void InitTexturePalette();
		void RefreshTexturePalette();
		
		// Brushes
		void InitBrushOptions();
		void ApplyBrushSize(int TX, int TY, int TSize);
		void ApplyBrush(int TX, int TY);
		void RenderBrush();
		void ResetFilters();

		// General
		int State;

		// Map
		CGMap *Map;

		// Textures
		array<ITexture *> TexturePalette;

		// Brush
		int BrushSize;
		TileStruct Brush;
		position2di BrushPosition;

		// Filters
		bool Filters[FILTER_COUNT];
};

#endif
